<!-- 王俊洁 “系统账单 - 提现记录” -->

<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="订单id" prop="orderId">-->
<!--        <el-input-->
<!--          v-model="queryParams.orderId"-->
<!--          placeholder="请输入订单id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

<!--   订单编号查订单（bug,待完成）   -->
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="theQueryWithdrawalRecords"
        />
      </el-form-item>

<!--   改为账户名Like查询（bug,待完成）   -->
      <el-form-item label="用户名" prop="accountId">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入用户名"
          clearable
          @keyup.enter.native="theQueryWithdrawalRecords"
        />
      </el-form-item>

<!--      <el-form-item label="有效字段" prop="flag">-->
<!--        <el-input-->
<!--          v-model="queryParams.flag"-->
<!--          placeholder="请输入有效字段"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="theQueryWithdrawalRecords">搜索</el-button>
<!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['expert:records:add']"
          :disabled="single"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['expert:records:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['expert:records:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['expert:records:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

<!--      点击了哪一行-->
    <el-table v-loading="loading" :data="recordsList" @selection-change="handleSelectionChange" @row-click="orderRow">
      <el-table-column type="selection" width="55" align="center"/>
<!--      <el-table-column label="id" align="center" prop="id" />-->

<!--   订单id改序号   -->
      <el-table-column label="序号" align="center" width="55">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>

<!--      <el-table-column label="订单id" align="center" prop="orderId" />-->
<!--      订单id改为订单号-->
      <el-table-column label="订单号" align="center" prop="orderNum"/>

<!--      <el-table-column label="账户id" align="center" prop="accountId" />-->
<!--      账户id改账户-->
      <el-table-column label="账户" align="center" prop="account"/>

<!--      用户名-->
      <el-table-column label="用户名" align="center" prop="nickName"/>

<!--      状态 （0待审核 1已撤回 2已完成 3已驳回 4待付款） -->
      <el-table-column label="状态" align="center" prop="state"/>

<!--      交易类型-->
      <el-table-column label="交易类型" align="center" prop="transactionType2"/>

<!--      <el-table-column label="有效字段" align="center" prop="flag" />-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['expert:records:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['expert:records:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

<!-- 遮罩层,覆盖整个页面，不允许触发事件 -->
    <div v-if="showOverlay" class="overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 999; display: flex; justify-content: center; align-items: center;">
      <!-- 订单详情页 -->
      <div style="background-color: white; width: 60%; border-radius: 8px;">
        <!--    标题样式    -->
        <div style="padding-left: 15px; display: flex; align-items: center;">
          <img width="60px" src="https://zyydt.oss-cn-chengdu.aliyuncs.com/vue/logo.jpg" alt="网络不佳，图片加载失败">
          <span style="padding-top: 6px; font-style: italic; font-family: '宋体', SimSun;">志愿之旅，智慧引航</span>
        </div>

        <!--    关闭按钮    -->
        <div style="position: relative;">
          <nav style="position: absolute; top: -45px; right: 10px; padding: 10px;">
            <a href="javascript:void(0)" style="text-decoration: none;">
              <span @click="showOverlay = false" style="font-size: 14px;">X</span>
            </a>
          </nav>
        </div>

        <!--    表格内容    -->
        <div style="display: block; padding-top: 20px; width: 90%; margin: auto;">
          <header>
            <span style="float: left">订单号：{{orderDetail.orderNum}}</span>
            <span style="float: right">交易日期：{{orderDetail.createTime}}</span>
            <nav style="width: 100%; padding-top: 25px; border-bottom: 1px solid black;"></nav>
          </header>

          <div style="display: flex; height: 100%;">
            <div style="width: 60%;">
              <p style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">单据类型：{{orderDetail.transactionType1}}</p>
              <p style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">提现账户：{{orderDetail.account}}</p>
              <p>账户名：{{orderDetail.nickName}}</p>
            </div>
            <div style="width: 40%; display: flex; align-items: center; justify-content: flex-end;">
              <p style="padding-right: 18px;">提现金额：￥{{orderDetail.money}}</p>
            </div>
          </div>
          <nav style="width: 100%; border-bottom: 1px solid black;"></nav>

          <div>
            <h3>订单信息：</h3>
            <!--      1、银行卡 2、微信 3、支付宝      -->
            <p>提交渠道：{{ orderDetail.type === "1" ? '银行卡' : orderDetail.type === "2" ? '微信' : orderDetail.type === "3" ? '支付宝' : '未知' }}</p>
            <p>用掉的代金券：{{orderDetail.voucher}}</p>
            <p>交易类型：{{orderDetail.transactionType2}}</p>
            <p>审核状态：{{orderDetail.state}}</p>
            <p>审核日期：{{orderDetail.reviewerTime}}</p>
            <p>意见：{{orderDetail.opinion}}</p>
            <p>备注：{{orderDetail.notes}}</p>
            <p style="padding-bottom: 10px;">订单支付信息：{{orderDetail.paymentInformation}}</p>
          </div>
        </div>

      </div>
    </div>


    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改批量生产卡对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单id" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单id" />
        </el-form-item>
        <el-form-item label="账户id" prop="accountId">
          <el-input v-model="form.accountId" placeholder="请输入账户id" />
        </el-form-item>
        <el-form-item label="有效字段" prop="flag">
          <el-input v-model="form.flag" placeholder="请输入有效字段" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRecords,
  getRecords,
  delRecords,
  addRecords,
  updateRecords,
  queryWithdrawalRecords
} from "@/api/expert/records";
import {ref} from "@vue/composition-api";
import HeaderSearch from "@/components/HeaderSearch/index.vue";

export default {
  name: "Records",
  components: {HeaderSearch},
  data() {
    return {
      // 订单详情
      orderDetail: {},
      // 查看订单页详情的遮罩层显示状态
      showOverlay: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 批量生产卡表格数据
      recordsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        accountId: null,
        flag: null,
        orderNo: "",// 订单号
        nickName:""// 用户名
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderId: [
          { required: true, message: "订单id不能为空", trigger: "blur" }
        ],
        accountId: [
          { required: true, message: "账户id不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.theQueryWithdrawalRecords();
  },
  methods: {
    /** 点击了哪一行 */
    orderRow(data){
      console.log("点击了哪一行：", data);
      this.showOverlay = true;
      this.orderDetail = data;
    },
    /** 查询批量生产卡列表,旧版（bug） */
    getList() {
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        console.log("旧版查询", response);
        this.recordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        accountId: null,
        createTime: null,
        updateTime: null,
        flag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作（旧版，bug） */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询提现记录（分页） */
    theQueryWithdrawalRecords(){
      this.loading = true;
      this.queryParams.pageNum = 1;
      queryWithdrawalRecords(this.queryParams.pageNum, this.queryParams.pageSize, this.queryParams.orderNo, this.queryParams.nickName).then(response => {
        console.log("拿到的数据：\t", response);
        this.recordsList = response.data.list;
        for (let i = 0; i < this.recordsList.length; i++) {
          if(this.recordsList[i].state == 0){
            this.recordsList[i].state = "待审核";
          }else if(this.recordsList[i].state == 1){
            this.recordsList[i].state = "已撤回";
          }else if(this.recordsList[i].state == 2){
            this.recordsList[i].state = "已完成";
          }else if(this.recordsList[i].state == 3){
            this.recordsList[i].state = "已驳回";
          }else if(this.recordsList[i].state == 4){
            this.recordsList[i].state = "待付款";
          }
        }
        console.log("准备渲染的对象", this.recordsList);
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.orderNo = "";
      this.queryParams.nickName = "";
      // this.handleQuery(); 旧版
      this.theQueryWithdrawalRecords();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加批量生产卡";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecords(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改批量生产卡";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRecords(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRecords(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除批量生产卡编号为"' + ids + '"的数据项？').then(function() {
        return delRecords(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('expert/records/export', {
        ...this.recordsList
      }, `records_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
